package rsp

import (
	"github.com/itstonight/ziyue/models"
)

// DocumentsToResponse 将文档列表转换为前端响应格式
func DocumentsToResponse(documents []models.Document) []map[string]interface{} {
	result := make([]map[string]interface{}, 0, len(documents))

	for _, doc := range documents {
		item := map[string]interface{}{
			"id":             doc.ID,
			"title":          doc.Title,
			"process":        doc.Process,
			"step":           doc.Step,
			"is_lock":        doc.IsLock,
			"locked_user_id": doc.LockedUserID,
			"created_at":     doc.CreatedAt,
			"updated_at":     doc.UpdatedAt,
		}

		// 处理锁定用户信息，去除敏感字段
		if doc.LockedUser != nil {
			item["locked_user"] = map[string]interface{}{
				"id":       doc.LockedUser.ID,
				"username": doc.LockedUser.Username,
				"role":     doc.LockedUser.Role,
			}
		}

		result = append(result, item)
	}

	return result
}
